package com.byq.mm.smartlib.service;


import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.byq.mm.smartlib.application.SmartApplication;
import com.byq.mm.smartlib.tools.NotificationHandlerImpl;

public class SmartConnectionService extends Service {

	SmartApplication application;





	

	@Override
	public void onCreate() {
		super.onCreate();

		application = (SmartApplication) this.getApplication();

	}

	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		boolean b =((SmartApplication) this.getApplication()).getAndroidSmartEngine().getXmppEngine().getConnectionManager().isLoggedIn();
		NotificationHandlerImpl.startService(this,b? 2:0);
	
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		application.getAndroidSmartEngine().getXmppEngine().getConnectionManager().logout();
		try {
			Thread.sleep(4000);
			
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		NotificationHandlerImpl.removeSevice(this);
	
	}

}
